import App from './App.vue'
import ElementUI from 'element-ui'
import router from'./router'
import 'element-ui/lib/theme-chalk/index.css'
import 'element-ui/lib/theme-chalk/display.css';
import axios from "axios";

import VueRouter from "vue-router";

import Vue from 'vue';


Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueRouter)

// 定义一个过滤器 处理时间
Vue.filter('dateFormat', function (originVal) {
  if (originVal==null||originVal==undefined||originVal=='') return '';
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  // 月份从0开始,使她变成字符串,不足两位时,前面补个0.
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

axios.interceptors.request.use(config => {
  if (window.localStorage.getItem('token')&&config.url.indexOf('login')==-1) {
    console.log(config)
    //判断token是否存在
    config.headers.token = window.localStorage.getItem('token');  //将token设置成请求头
  }

  return config;

})
axios.defaults.withCredentials = true
new Vue({
  router,

  render: h => h(App),
  beforeCreate(){
    Vue.prototype.$bus=this;
  }
}).$mount('#app')
